﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MapFileEncoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("*******************MapFileEncoder*****************");
            //读取文件夹
            string srcDir = AppDomain.CurrentDomain.BaseDirectory + "src";
            string srcDist = AppDomain.CurrentDomain.BaseDirectory + "dist";
            if (Directory.Exists(srcDir))
            {
                if (!Directory.Exists(srcDist))
                {
                    Directory.CreateDirectory(srcDist);
                }
                DirectoryInfo dirInfo = new DirectoryInfo(srcDir);
                foreach (FileInfo fileInfo in dirInfo.GetFiles("*.map"))
                {
                    StreamReader sr = new StreamReader(fileInfo.FullName, Encoding.UTF8);
                    StreamWriter sw = new StreamWriter(srcDist + @"\" + fileInfo.Name, false, Encoding.UTF8);
                    try
                    {
                        string line = sr.ReadLine();
                        while (!string.IsNullOrEmpty(line))
                        {
                            string b64Line = Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes(line));
                            sw.WriteLine(b64Line);
                            line = sr.ReadLine();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        sr.Close();
                        sw.Flush();
                        sw.Close();
                    }
                }
            }
            else
            {
                Console.WriteLine("no src dir");
            }

            Console.WriteLine("Completed");
            Console.ReadLine();
        }


    }
}
